package com.lbs.jiepiaisi.activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.lbs.jiepiaisi.R;
import com.lbs.jiepiaisi.base.BaseActivity;
import com.lbs.jiepiaisi.bean.EquipmentEntity;
import com.lbs.jiepiaisi.bean.LocationBean;
import com.lbs.jiepiaisi.bean.TrackEntity;
import com.lbs.jiepiaisi.biz.LocationBiz;
import com.lbs.jiepiaisi.biz.SelCarsBiz;
import com.lbs.jiepiaisi.biz.TrackBiz;
import com.lbs.jiepiaisi.manager.MyPoiOverlay;
import com.lbs.jiepiaisi.manager.SharePreferenceManager;
import com.lbs.jiepiaisi.utils.ButtonUtil;
import com.lbs.jiepiaisi.utils.Constant;
import com.lbs.jiepiaisi.utils.WindowSizeUtil;
import com.lbs.jiepiaisi.view.WaitingDialogControll;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 *
 * 时间：2017/6/26 10:42
 * 作用：平台主页面
 */

public class AccountSearchActivity extends BaseActivity implements AMapLocationListener,
        AMap.OnMapClickListener,AMap.OnMarkerClickListener,
        View.OnClickListener,AMap.InfoWindowAdapter,GeocodeSearch.OnGeocodeSearchListener {

    private MapView mapView;//地图
    private AMap aMap;//地图控制器对象
    private static int flag=0;//infowindow点击更多切换按钮状态
    private LinearLayout liner_search;//搜索
    private SelCarsReceiver selCarsReceiver;//接收坐标点的广播
    private TrackReceiver trackReceiver;//接收实时跟踪中的接口数据广播
    private LocationReceiver locationReceiver;//接收根据经纬度查询的位置信息
    private EquipmentEntity equipmentEntity;
    private TrackEntity trackEntity;
    private List<EquipmentEntity.Result.Item> listItem = new ArrayList<>();
    private SharePreferenceManager mSharePreference=null;
    private GeocodeSearch geocodeSearch;//逆地理编码转换对象
    private String addressName;//当前地址
    private String possionTime;//当前定位时间
    MyPoiOverlay poiOverlay;
    private View popView; //显示弹框
    private ImageButton mLocationBtn;
    private HashMap<Integer,Boolean> locationFlag = new HashMap<>();

    private float currentZoom = 13;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        isTemplate = true;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_platform_search_account);
        mapView = (MapView) findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);// 此方法必须重写
        selCarsReceiver=new SelCarsReceiver();
        getApplicationContext().registerReceiver(selCarsReceiver, new IntentFilter(Constant.ACCOUNT_SEARCH_SELCARS));
        trackReceiver=new TrackReceiver();
        getApplicationContext().registerReceiver(trackReceiver, new IntentFilter(Constant.ACCOUNT_SEARCH_TRACK));
        locationReceiver = new LocationReceiver();
        getApplicationContext().registerReceiver(locationReceiver, new IntentFilter(Constant.ACCOUNT_SEARCH_LAT_LNG));
        mSharePreference=SharePreferenceManager.getInstance(mContext);
        getExras();
        findView();
        setListener();
    }


    //加载网络数据
    public void getExras() {
        WaitingDialogControll.showWaitingDialog(this);
        SelCarsBiz selCarsBiz=new SelCarsBiz();
        String str = getIntent().getStringExtra("resultString");
        selCarsBiz.selCarsBiz(str,"1","1000",false,Constant.ACCOUNT_SEARCH_SELCARS);
    }
    private void findView() {
        mLocationBtn = (ImageButton) findViewById(R.id.btn_location);

        //初始化地图控制器
        if (aMap == null) {
            aMap = mapView.getMap();
            liner_search= (LinearLayout) findViewById(R.id.liner_search);
            //禁止地图旋转手势
            aMap.getUiSettings().setRotateGesturesEnabled(false);
            aMap.setOnMapClickListener(this);//对amap添加单击地图事件监听器
            aMap.setOnMarkerClickListener(this);// 设置点击marker事件监听器
            aMap.setInfoWindowAdapter(this);// 设置自定义InfoWindow样式
            aMap.getUiSettings().setLogoBottomMargin(-50);

        }
        aMap.clear();
    }

    private void setListener() {

        mLocationBtn.setOnClickListener(this);

        aMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {
            @Override
            public void onCameraChange(CameraPosition cameraPosition) {

            }

            @Override
            public void onCameraChangeFinish(CameraPosition cameraPosition) {
                currentZoom = cameraPosition.zoom;
            }
        });
    }
    @Override
    public void onClick(View v) {
//        switch (v.getId()) {
//            case R.id.liner_list://列表
//                  if(ButtonUtil.isFastClick()){
//                      IntentUtil.gotoActivity(mContext,AccountListActivity.class,false);
//                  }
//                break;
//            case R.id.liner_warning://报警
//                if(ButtonUtil.isFastClick()){
//                    IntentUtil.gotoActivity(mContext,AccountAllNoticeActivity.class,false);
//                }
//                break;
//            case R.id.liner_me://我的
//                if(ButtonUtil.isFastClick()){
//                    IntentUtil.gotoActivity(mContext,AccountMyActivity.class,false);
//                }
//                break;
//
//            case R.id.liner_search://搜素
//                if(ButtonUtil.isFastClick()){
//                    closeShowDialog(showMarker);
//                    IntentUtil.gotoActivity(mContext, EquipSearchActivity.class, false);
//                }
//                break;
//            case R.id.btn_location:{
//                if(ButtonUtil.isFastClick()){
//                    closeShowDialog(showMarker);
//                    initLocation();
//                }
//                break;
//            }
//        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
        getApplicationContext().unregisterReceiver(selCarsReceiver);
        getApplicationContext().unregisterReceiver(trackReceiver);
        getApplicationContext().unregisterReceiver(locationReceiver);
    }
    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        mapView.onResume();
    }
    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mapView.onPause();
    }
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mapView.onSaveInstanceState(outState);
    }

    private Marker showMarker = null;
    /**
     * 地图点击事件回调方法
     */
    @Override
    public void onMapClick(LatLng latLng) {
        log_e("地图被点击了！！");
        if (null != showMarker && showMarker.isInfoWindowShown()) {
            showMarker.hideInfoWindow();//这个是隐藏infowindow窗口的方法
        }
    }
    /**
     * Mark点击事件回调方法
     */
    @Override
    public boolean onMarkerClick(Marker marker) {
        int position = Integer.valueOf(marker.getTitle());
        if(locationFlag.get(position) == null || !locationFlag.get(position)){
            locationFlag.put(position,true);
            final TrackBiz trackBiz=new TrackBiz();
            trackBiz.trackBiz(listItem.get(position).getEqNo(),listItem.get(position),null,Constant.ACCOUNT_SEARCH_TRACK,true);
        }else {
            isShowDialog(marker);
        }
        return false;//返回:  :表示点击marker后,marker不会移动到地图中心；返回false表示点击marker后,marker会自动移动到地图中心。
    }
    public void isShowDialog(Marker marker){
        // 设置地图中心点在屏幕的位置
        showMarker = marker;
        if (marker.isInfoWindowShown()) {
            marker.hideInfoWindow();
        }else{
            aMap.setPointToCenter(WindowSizeUtil.getWidth(mContext) / 2, WindowSizeUtil.getHeight(mContext) / 5 * 4);
            marker.showInfoWindow();
            aMap.moveCamera(CameraUpdateFactory.zoomTo(currentZoom));
            aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(marker.getPosition().latitude, marker.getPosition().longitude)));
        }

    }
    public void closeShowDialog(Marker marker){
        // 设置地图中心点在屏幕的位置
        showMarker = marker;
        if (marker != null && marker.isInfoWindowShown()) {
            marker.hideInfoWindow();
        }
    }
    /**
     *设置自定义InfoWindow样式的回调方法
     * infocontents事件回调
     * 注意：API优先回调getInfoWindow ，如果返回的是null，会再回调getInfoContents。
     */
    @Override
    public View getInfoWindow(Marker marker) {
        int possion = Integer.valueOf(marker.getTitle());
        return getInfoView(possion);
    }



    /**
     *设置自定义InfoWindow样式的回调方法
     * infowindow事件回调
     */
    @Override
    public View getInfoContents(Marker marker) {
        return  null;
    }
    private View getInfoView(final int possion) {
        final View view = LayoutInflater.from(mContext).inflate(R.layout.layout_marker_infowindow, null);
        popView = view;
        //不显示更多选项
        view.findViewById(R.id.liner_info_below).setVisibility(View.GONE);
        //设置车主姓名
        ((TextView)view.findViewById(R.id.tv_driverName)).setText(listItem.get(possion).getOwnerName());
        //设置设备编号
        ((TextView)view.findViewById(R.id.tv_eqno)).setText(listItem.get(possion).getEqNo());
        //存储设备状态
        mSharePreference.put(Constant.ACCOUNT_STATUS,listItem.get(possion).getStatus());
        //存储车主姓名
        mSharePreference.put(Constant.ACCOUNT_NAME,listItem.get(possion).getOwnerName());

        ((TextView)view.findViewById(R.id.tv_time)).setText(possionTime);


        ((TextView)view.findViewById(R.id.tv_dress)).setText(addressName);



        //存储定位时间

//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                // 模拟耗时的操作,保证地址加载完成后进行赋值
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                // 更新主线程ＵＩ
//                runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//
//                    }
//                });
//
//            }
//        }).start();

//        //存储速度
//
//        //存储当前地址（通过经纬度转换为地理位置）
//        double lat=listItem.get(possion).getPoint().getLat();
//        double lng=listItem.get(possion).getPoint().getLng();
//        LatLonPoint latLonPoint=new LatLonPoint(lat,lng);
//        geocodeSearch=new GeocodeSearch(this);
//        geocodeSearch.setOnGeocodeSearchListener(this);
//        // 第一个参数表示一个Latlng，第二参数表示范围多少米，第三个参数表示是火系坐标系还是GPS原生坐标系
//        RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200,GeocodeSearch.AMAP);
//        geocodeSearch.getFromLocationAsyn(query);
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                // 模拟耗时的操作,保证地址加载完成后进行赋值
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                // 更新主线程ＵＩ
//               runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//
//                    }
//                });
//
//            }
//        }).start();
        /**
         * 设置按钮点击事件
         */
        //更多
         view.findViewById(R.id.liner_info_more).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 if(flag==0){//点击全选
                     flag=1;
                     //显示更多选项
                     view.findViewById(R.id.liner_info_below).setVisibility(View.VISIBLE);
                 }else{
                     flag=0;
                     //显示更多选项
                     view.findViewById(R.id.liner_info_below).setVisibility(View.GONE);
                 }
             }
         });
        //历史轨迹
        view.findViewById(R.id.liner_history).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonUtil.isFastClick()) {
                    // IntentUtil.gotoActivity(mContext,HistoryTraceActivity.class,false,map);
                    Intent intent = new Intent();
                    intent.putExtra("eqNo", listItem.get(possion).getEqNo());//存入当前设备
                    intent.putExtra("carName",listItem.get(possion).getOwnerName());//存入当前车主姓名
                    intent.setClass(mContext, HistoryTraceActivity.class);
                    startActivity(intent);
                }
            }
        });
        //一键追车
        view.findViewById(R.id.liner_navi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonUtil.isFastClick()) {
                    Intent intent=new Intent(mContext,AccountChaseCarAcitivty.class);
                    TrackEntity data = new TrackEntity();
                    TrackEntity.Result dataResult = new TrackEntity.Result();
                    dataResult.setGdLat(listItem.get(possion).getPoint().getLat());
                    dataResult.setGdLng(listItem.get(possion).getPoint().getLng());
                    ArrayList<TrackEntity.Result> results = new ArrayList<>();
                    results.add(dataResult);
                    data.setResults(results);
                    intent.putExtra(Constant.ACCOUNT_NAVIGATION, data);
                    startActivity(intent);
                }
            }
        });
        //重新定位
        view.findViewById(R.id.liner_reposition).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonUtil.isFastClick()) {
                    WaitingDialogControll.showWaitingDialog(mContext);
                    //开启刷新状态
                    isShowDialog(showMarker);
                    final TrackBiz trackBiz=new TrackBiz();
                    trackBiz.trackBiz(listItem.get(possion).getEqNo(),listItem.get(possion),null,Constant.ACCOUNT_SEARCH_TRACK,true);
                }
            }
        });
        //实时跟踪
        view.findViewById(R.id.liner_track).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(ButtonUtil.isFastClick()){
                   // WaitingDialogControll.showWaitingDialog(mContext);
                    Intent intent = new Intent();
                    intent.putExtra("eqNo", listItem.get(possion).getEqNo());//存入当前设备
                    intent.putExtra("ownerName",listItem.get(possion).getOwnerName());
                    intent.setClass(mContext, TracingActivity.class);
                    startActivity(intent);
                }
            }
        });
        //单个设备告警
        view.findViewById(R.id.liner_notice).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(ButtonUtil.isFastClick()){
                    Intent intent=new Intent();
                    intent.putExtra("eqNo", listItem.get(possion).getEqNo());//存入当前设备编码
                    intent.putExtra("deptId",listItem.get(possion).getDeptId());//存入当前部门编码
                    intent.putExtra("eqName",listItem.get(possion).getOwnerName());//存入姓名
                    intent.setClass(mContext, AlarmListActivity.class);
                    startActivity(intent);

                }
            }
        });

        //用户信息
        view.findViewById(R.id.liner_user_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(ButtonUtil.isFastClick()){
                    Intent intent=new Intent();
                    intent.putExtra("eqNo", listItem.get(possion).getEqNo());//设备号
                    intent.putExtra("deptId",listItem.get(possion).getDeptId());//型号
                    intent.setClass(mContext, AccountUserInfoActivity.class);
                    startActivity(intent);

                }
            }
        });


        return view;
    }

    /**
     * 通过经纬度转化为地理位置
     */
    @Override
    public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
        if (rCode == 1000) {
            if (result != null && result.getRegeocodeAddress() != null
                    && result.getRegeocodeAddress().getFormatAddress() != null) {
                addressName = result.getRegeocodeAddress().getFormatAddress() + "附近";
            } else {
                addressName="当前地址获取失败";
            }
        } else {
               addressName="当前地址获取失败";
        }
    }

    @Override
    public void onGeocodeSearched(GeocodeResult result, int rCode) {

    }

    class SelCarsReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            WaitingDialogControll.dismissWaitingDialog();

            equipmentEntity=(EquipmentEntity) intent.
                    getSerializableExtra(Constant.KEY_DATA);
            Boolean isReload = intent.
                    getBooleanExtra(Constant.KEY_DATA2,false);
            if(equipmentEntity.getCode()==Constant.STATUS_OK){
                    //Toast.makeText(mContext, "加载成功", Toast.LENGTH_SHORT).show();
                titleView.setText(equipmentEntity.getResult().getItems().get(0).getOwnerName());
                if(!isReload){
                    if(equipmentEntity.getPage() == 1){
                        listItem.clear();
                    }
                    List<EquipmentEntity.Result.Item> items = equipmentEntity.getResult().getItems();
                    for(EquipmentEntity.Result.Item item : items){
                        if(item.getPoint() != null){
                            listItem.add(item);
                        }
                    }
                    markCarsOnMap(listItem,false);
                }else {
                    if(equipmentEntity.getResult().getItems().size() > 0){
                        EquipmentEntity.Result.Item item = equipmentEntity.getResult().getItems().get(0);
                        for(EquipmentEntity.Result.Item itemTemp : listItem){

                            if(itemTemp.getEqNo().equals(item.getEqNo())){
                                itemTemp.setDeptId(item.getDeptId());
                                itemTemp.setStatus(item.getStatus());
                                itemTemp.setPoint(item.getPoint());
                                itemTemp.setContractNo(item.getContractNo());
                                itemTemp.setGiveValue(item.getGiveValue());
                                itemTemp.setOwnerName(item.getOwnerName());
                                itemTemp.setPlateNum(item.getPlateNum());
                            }

                        }
                        poiOverlay.changeToMap(listItem);
                        //isShowDialog(showMarker);
                    }
                }

            }

            else if(equipmentEntity.getCode()==Constant.STATUS_NETWORK_ERROR){
                Toast.makeText(mContext, "加载失败", Toast.LENGTH_SHORT).show();
            }else if(equipmentEntity.getCode()==Constant.STATUS_NO_NET){
                Toast.makeText(mContext, "请检查网络", Toast.LENGTH_SHORT).show();
            }

        }
    }
    /**
     * 设置Markers方法
     */

    private void markCarsOnMap(List<EquipmentEntity.Result.Item> items,boolean isLoadMore) {
        if(!isLoadMore){
            aMap.clear();
        }
        List<BitmapDescriptor> b = MyPoiOverlay.getBitmap(items,mContext);//设置图片状态
        poiOverlay = new MyPoiOverlay(aMap, items, b, (WindowSizeUtil.getWidth(mContext)) / 8);//通过自定的Mark管理类poiOverlay来管理
        poiOverlay.removeFromMap();
        poiOverlay.addToMap();
        poiOverlay.zoomToSpan();
    }


    private int delItemOld(EquipmentEntity.Result.Item item){
        for(int i = 0; i < listItem.size() ;i ++){
            if(listItem.get(i).getEqNo().equals(item.getEqNo())){
                listItem.remove(i);
                return i;
            }
        }
        return  0;
    }
    private EquipmentEntity.Result.Item itemNew;
    //声明mlocationClient对象
    public AMapLocationClient mlocationClient;
    //声明mLocationOption对象
    public AMapLocationClientOption mLocationOption = null;

    AMapLocation aMapLocation = null;
    public void initLocation() {
        mlocationClient = new AMapLocationClient(this);
        //初始化定位参数
        mLocationOption = new AMapLocationClientOption();
        //设置定位监听
        mlocationClient.setLocationListener(this);
        //设置定位模式为高精度模式，Battery_Saving为低功耗模式，Device_Sensors是仅设备模式
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //设置定位间隔,单位毫秒,默认为2000ms
        mLocationOption.setOnceLocation(true);
        //设置定位参数
        mlocationClient.setLocationOption(mLocationOption);
        // 此方法为每隔固定时间会发起一次定位请求，为了减少电量消耗或网络流量消耗，
        // 注意设置合适的定位时间的间隔（最小间隔支持为1000ms），并且在合适时间调用stopLocation()方法来取消定位请求
        // 在定位结束后，在合适的生命周期调用onDestroy()方法
        // 在单次定位情况下，定位无论成功与否，都无需调用stopLocation()方法移除请求，定位sdk内部会移除
        //启动定位
        mlocationClient.startLocation();
    }
    @Override
    public void onLocationChanged(AMapLocation aMapLocation) {
        Log.e("TAG", "地理位置信息：" + aMapLocation);
        this.aMapLocation = aMapLocation;
        aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude())));

    }
    //接收实时跟踪数据的广播
    class TrackReceiver extends BroadcastReceiver{
        @Override
        public void onReceive(Context context, Intent intent) {
            trackEntity=(TrackEntity) intent.
                    getSerializableExtra(Constant.KEY_DATA);
            itemNew = (EquipmentEntity.Result.Item) intent.
                    getSerializableExtra(Constant.KEY_DATA2);
            if(trackEntity != null && trackEntity.getResults() != null &&  trackEntity.getResults().size() > 0){
                if(!trackEntity.getResults().get(0).getImportTime().equals("null")){
                    possionTime=trackEntity.getResults().get(0).getImportTime();

                }else{
                    possionTime="未上传定位时间";
                }
                if(popView != null){
                    ((TextView)popView.findViewById(R.id.tv_time)).setText(trackEntity.getResults().get(0).getImportTime());
                    ((TextView)popView.findViewById(R.id.tv_post_type)).setText(trackEntity.getResults().get(0).getPostType());
                    String status = trackEntity.getResults().get(0).getStatus();
                    if("2".equals(status)){
                        ((TextView)popView.findViewById(R.id.tv_flag)).setText("离线");
                    }else if("3".equals(status)){
                        ((TextView)popView.findViewById(R.id.tv_flag)).setText("未启用");
                    }else  {
                        ((TextView)popView.findViewById(R.id.tv_flag)).setText("在线");
                    }
                    new LocationBiz().getAddRessWithLatAndLng(trackEntity.getResults().get(0).getGdLat(),trackEntity.getResults().get(0).getGdLng(),Constant.ACCOUNT_SEARCH_LAT_LNG);
                    if(itemNew != null) {
                        itemNew.getPoint().setLat(trackEntity.getResults().get(0).getGdLat());
                        itemNew.getPoint().setLng(trackEntity.getResults().get(0).getGdLng());
                        itemNew.getPoint().setRoate(trackEntity.getResults().get(0).getDir());
                        int position = delItemOld(itemNew);
                        listItem.add(position,itemNew);
                        markCarsOnMap(listItem,false);
                        showMarker = poiOverlay.getMarkerByPosition(position);
                        //isShowDialog(showMarker);

                        aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(trackEntity.getResults().get(0).getGdLat(), trackEntity.getResults().get(0).getGdLng())));
                    }
                }
            }

        }
    }
    class LocationReceiver extends BroadcastReceiver{
        @Override
        public void onReceive(Context context, Intent intent) {
            WaitingDialogControll.dismissWaitingDialog();
            LocationBean locationBean =(LocationBean) intent.
                    getSerializableExtra(Constant.KEY_DATA);
            if(locationBean.getStatus() == Constant.STATUS_OK){
                if(popView != null){
                    TextView tvAddress = ((TextView)popView.findViewById(R.id.tv_dress));
                    if(tvAddress != null){
                        tvAddress.setText(locationBean.getRegeocode().getFormatted_address());
                    }
                    addressName = locationBean.getRegeocode().getFormatted_address();
                    isShowDialog(showMarker);

                }

            }

        }
    }
}

